package serve;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class ChatdbConnector
{
    private static Connection chatdb_connection;

    public ChatdbConnector()
    {
        set_SQLConnection();
    }

    public Connection getChatdb_connection()
    {
        return chatdb_connection;
    }

    public void set_SQLConnection()
    {
        try
        {
            Class.forName("com.mysql.cj.jdbc.Driver");  //加载数据库驱动
            String url="jdbc:mysql://localhost:3306/chatdb?autoReconnect=true&allowPublicKeyRetrieval=true&useSSL=false";   //此处为服务器上数据库连接
            String username=Constant.username;  //数据库用户名
            String passwd=Constant.passwd;      //数据库密码
            chatdb_connection = DriverManager.getConnection(url,username,passwd); //建立连接
        } catch (ClassNotFoundException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (SQLException e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}
